﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{
    public class CLSMAEPRO
    {
        string codref_pro, codcol_pro, codtal_pro, codbar_pro, codpro_pro;

        public string CODREF_PRO
        {
            get { return codref_pro; }
            set { codref_pro = value; }
        }
        public string CODCOL_PRO
        {
            get { return codcol_pro; }
            set { codcol_pro = value; }
        }
        public string CODTAL_PRO
        {
            get { return codtal_pro; }
            set { codtal_pro = value; }
        }
        public string CODBAR_PRO
        {
            get { return codbar_pro; }
            set { codbar_pro = value; }
        }
        public string CODPRO_PRO
        {
            get { return codpro_pro; }
            set { codpro_pro = value; }
        }

        MDOgeneral mod = new MDOgeneral();

        public void consultarCodBarras()
        {
            try
            {
                string query = "select CODREF_PRO, CODCOL_PRO, CODTAL_PRO from USU_DBA.maepro where CODBAR_PRO = '" + CODBAR_PRO + "'";
                DataTable dt = mod.consulta(query);
                if (dt.Rows.Count > 0)
                {
                    CODREF_PRO = dt.Rows[0]["CODREF_PRO"].ToString(); ;
                    CODCOL_PRO = dt.Rows[0]["CODCOL_PRO"].ToString();
                    CODTAL_PRO = dt.Rows[0]["CODTAL_PRO"].ToString();
                }
            }
            catch (Exception ex) { throw ex; }
        }

        public DataTable BuscarColor()
        {
            try
            {
                string query = "select distinct codcol_pro as Codigo, nomcol_col as nombre, 0 as existencia from USU_DBA.maepro inner join USU_DBA.maecol on codcol_pro=codcol_col where codref_pro='" + CODREF_PRO + "' Order by nomcol_col";
                return mod.consulta(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable BuscarTallas()
        {
            try
            {
                 string query = "select distinct codtal_pro as talla from USU_DBA.maepro where codref_pro='" + CODREF_PRO + "' and codcol_pro='" + CODCOL_PRO + "' order by codtal_pro asc";  
                 return mod.consulta(query);
	        }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable ConsTallaje() {
            try
            {
                string query = "Select POSTAL_TAL,CODTAL_TAL,CODTAL_PRO from (Select CODTJE_TAL,CODTAL_TAL,POSTAL_TAL from TALTAL where CODTJE_TAL=(Select TALREF_REF from USU_DBA.MAEREF where CODREF_REF='" + CODREF_PRO + "')) A LEFT OUTER JOIN (Select DISTINCT CODTAL_PRO from USU_DBA.MAEPRO where CODREF_PRO='" + CODREF_PRO + "') B ON CODTAL_TAL=CODTAL_PRO order by POSTAL_TAL";
                return mod.consulta(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


    }
}
